package com.tml.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tml.dao.SmbmsUserDao;
import com.tml.entry.SmbmsRole;
import com.tml.entry.SmbmsUser;
import com.tml.service.SmbmsUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class SmbmsUserServiceImpl implements SmbmsUserService {

   @Autowired
   SmbmsUserDao smbmsUserDao;
    @Override
    public List<SmbmsUser> getSmbmsUserAll() {

        List<SmbmsUser>  smbmsUserList =   smbmsUserDao.getSmbmsUserAll();

        return smbmsUserList;
    }
    @Override
    public List<SmbmsRole> getSmbmsRoleAll() {
    List<SmbmsRole>  smbmsRoleList =   smbmsUserDao.getSmbmsRoleAll();

    return smbmsRoleList;
    }

    @Override
    public IPage<SmbmsUser> getSmbmsUserByPage(Page page, SmbmsUser smbmsUser) {
        QueryWrapper queryWrapper=new QueryWrapper();
        if (smbmsUser.getUserName()!=null){
        queryWrapper.like("userName",smbmsUser.getUserName());
        }
        if (smbmsUser.getUserRole()!=null&&smbmsUser.getUserRole()!=0){
        queryWrapper.eq("userRole",smbmsUser.getUserRole());}
        return smbmsUserDao.selectPage(page,queryWrapper);
    }

    @Override
    public void addSmbmsUser(SmbmsUser smbmsUser) {
        smbmsUserDao.addSmbmsUser(smbmsUser);
    }

    @Override
    public void updSmbmsUser(SmbmsUser smbmsUser) {
        smbmsUserDao.updSmbmsUser(smbmsUser);

    }

    @Override
    public void delSmbmsUser(Long id) {
        smbmsUserDao.delSmbmsUser(id);
    }

    @Override
    public SmbmsUser getSmbmsUserById(Long id) {
        SmbmsUser smbmsUser =   smbmsUserDao.getSmbmsUserById(id);
        return smbmsUser;
    }
}
